<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>vendor_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_dom_vendor_test.js.html">vendor_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2012 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.dom.vendorTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.dom.vendorTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.array&#39;);
<a name="line19"></a>goog.require(&#39;goog.dom.vendor&#39;);
<a name="line20"></a>goog.require(&#39;goog.labs.userAgent.util&#39;);
<a name="line21"></a>goog.require(&#39;goog.testing.MockUserAgent&#39;);
<a name="line22"></a>goog.require(&#39;goog.testing.PropertyReplacer&#39;);
<a name="line23"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line24"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line25"></a>goog.require(&#39;goog.userAgentTestUtil&#39;);
<a name="line26"></a>
<a name="line27"></a>var documentMode;
<a name="line28"></a>var mockUserAgent;
<a name="line29"></a>var propertyReplacer = new goog.testing.PropertyReplacer();
<a name="line30"></a>
<a name="line31"></a>function setUp() {
<a name="line32"></a>  mockUserAgent = new goog.testing.MockUserAgent();
<a name="line33"></a>  mockUserAgent.install();
<a name="line34"></a>}
<a name="line35"></a>
<a name="line36"></a>function tearDown() {
<a name="line37"></a>  goog.dispose(mockUserAgent);
<a name="line38"></a>  documentMode = undefined;
<a name="line39"></a>  propertyReplacer.reset();
<a name="line40"></a>}
<a name="line41"></a>
<a name="line42"></a>goog.userAgent.getDocumentMode_ = function() {
<a name="line43"></a>  return documentMode;
<a name="line44"></a>};
<a name="line45"></a>
<a name="line46"></a>
<a name="line47"></a>var UserAgents = {
<a name="line48"></a>  GECKO: &#39;GECKO&#39;,
<a name="line49"></a>  IE: &#39;IE&#39;,
<a name="line50"></a>  OPERA: &#39;OPERA&#39;,
<a name="line51"></a>  WEBKIT: &#39;WEBKIT&#39;
<a name="line52"></a>};
<a name="line53"></a>
<a name="line54"></a>
<a name="line55"></a>/**
<a name="line56"></a> * Return whether a given user agent has been detected.
<a name="line57"></a> * @param {number} agent Value in UserAgents.
<a name="line58"></a> * @return {boolean} Whether the user agent has been detected.
<a name="line59"></a> */
<a name="line60"></a>function getUserAgentDetected_(agent) {
<a name="line61"></a>  switch (agent) {
<a name="line62"></a>    case UserAgents.GECKO:
<a name="line63"></a>      return goog.userAgent.GECKO;
<a name="line64"></a>    case UserAgents.IE:
<a name="line65"></a>      return goog.userAgent.IE;
<a name="line66"></a>    case UserAgents.OPERA:
<a name="line67"></a>      return goog.userAgent.OPERA;
<a name="line68"></a>    case UserAgents.WEBKIT:
<a name="line69"></a>      return goog.userAgent.WEBKIT;
<a name="line70"></a>  }
<a name="line71"></a>  return null;
<a name="line72"></a>}
<a name="line73"></a>
<a name="line74"></a>
<a name="line75"></a>/**
<a name="line76"></a> * Test browser detection for a user agent configuration.
<a name="line77"></a> * @param {Array.&lt;number&gt;} expectedAgents Array of expected userAgents.
<a name="line78"></a> * @param {string} uaString User agent string.
<a name="line79"></a> * @param {string=} opt_product Navigator product string.
<a name="line80"></a> * @param {string=} opt_vendor Navigator vendor string.
<a name="line81"></a> */
<a name="line82"></a>function assertUserAgent(expectedAgents, uaString, opt_product, opt_vendor) {
<a name="line83"></a>  var mockNavigator = {
<a name="line84"></a>    &#39;userAgent&#39;: uaString,
<a name="line85"></a>    &#39;product&#39;: opt_product,
<a name="line86"></a>    &#39;vendor&#39;: opt_vendor
<a name="line87"></a>  };
<a name="line88"></a>
<a name="line89"></a>  mockUserAgent.setNavigator(mockNavigator);
<a name="line90"></a>  mockUserAgent.setUserAgentString(uaString);
<a name="line91"></a>
<a name="line92"></a>  // Force reread of navigator.userAgent;
<a name="line93"></a>  goog.labs.userAgent.util.setUserAgent(null);
<a name="line94"></a>  goog.userAgentTestUtil.reinitializeUserAgent();
<a name="line95"></a>  for (var ua in UserAgents) {
<a name="line96"></a>    var isExpected = goog.array.contains(expectedAgents, UserAgents[ua]);
<a name="line97"></a>    assertEquals(isExpected, getUserAgentDetected_(UserAgents[ua]));
<a name="line98"></a>  }
<a name="line99"></a>}
<a name="line100"></a>
<a name="line101"></a>
<a name="line102"></a>/**
<a name="line103"></a> * Tests for the vendor prefix for Webkit.
<a name="line104"></a> */
<a name="line105"></a>function testVendorPrefixWebkit() {
<a name="line106"></a>  assertUserAgent([UserAgents.WEBKIT], &#39;WebKit&#39;);
<a name="line107"></a>  assertEquals(&#39;-webkit&#39;, goog.dom.vendor.getVendorPrefix());
<a name="line108"></a>}
<a name="line109"></a>
<a name="line110"></a>
<a name="line111"></a>/**
<a name="line112"></a> * Tests for the vendor prefix for Mozilla/Gecko.
<a name="line113"></a> */
<a name="line114"></a>function testVendorPrefixGecko() {
<a name="line115"></a>  assertUserAgent([UserAgents.GECKO], &#39;Gecko&#39;, &#39;Gecko&#39;);
<a name="line116"></a>  assertEquals(&#39;-moz&#39;, goog.dom.vendor.getVendorPrefix());
<a name="line117"></a>}
<a name="line118"></a>
<a name="line119"></a>
<a name="line120"></a>/**
<a name="line121"></a> * Tests for the vendor prefix for Opera.
<a name="line122"></a> */
<a name="line123"></a>function testVendorPrefixOpera() {
<a name="line124"></a>  assertUserAgent([UserAgents.OPERA], &#39;Opera&#39;);
<a name="line125"></a>  assertEquals(&#39;-o&#39;, goog.dom.vendor.getVendorPrefix());
<a name="line126"></a>}
<a name="line127"></a>
<a name="line128"></a>
<a name="line129"></a>/**
<a name="line130"></a> * Tests for the vendor prefix for IE.
<a name="line131"></a> */
<a name="line132"></a>function testVendorPrefixIE() {
<a name="line133"></a>  assertUserAgent([UserAgents.IE], &#39;MSIE&#39;);
<a name="line134"></a>  assertEquals(&#39;-ms&#39;, goog.dom.vendor.getVendorPrefix());
<a name="line135"></a>}
<a name="line136"></a>
<a name="line137"></a>
<a name="line138"></a>/**
<a name="line139"></a> * Tests for the vendor Js prefix for Webkit.
<a name="line140"></a> */
<a name="line141"></a>function testVendorJsPrefixWebkit() {
<a name="line142"></a>  assertUserAgent([UserAgents.WEBKIT], &#39;WebKit&#39;);
<a name="line143"></a>  assertEquals(&#39;Webkit&#39;, goog.dom.vendor.getVendorJsPrefix());
<a name="line144"></a>}
<a name="line145"></a>
<a name="line146"></a>
<a name="line147"></a>/**
<a name="line148"></a> * Tests for the vendor Js prefix for Mozilla/Gecko.
<a name="line149"></a> */
<a name="line150"></a>function testVendorJsPrefixGecko() {
<a name="line151"></a>  assertUserAgent([UserAgents.GECKO], &#39;Gecko&#39;, &#39;Gecko&#39;);
<a name="line152"></a>  assertEquals(&#39;Moz&#39;, goog.dom.vendor.getVendorJsPrefix());
<a name="line153"></a>}
<a name="line154"></a>
<a name="line155"></a>
<a name="line156"></a>/**
<a name="line157"></a> * Tests for the vendor Js prefix for Opera.
<a name="line158"></a> */
<a name="line159"></a>function testVendorJsPrefixOpera() {
<a name="line160"></a>  assertUserAgent([UserAgents.OPERA], &#39;Opera&#39;);
<a name="line161"></a>  assertEquals(&#39;O&#39;, goog.dom.vendor.getVendorJsPrefix());
<a name="line162"></a>}
<a name="line163"></a>
<a name="line164"></a>
<a name="line165"></a>/**
<a name="line166"></a> * Tests for the vendor Js prefix for IE.
<a name="line167"></a> */
<a name="line168"></a>function testVendorJsPrefixIE() {
<a name="line169"></a>  assertUserAgent([UserAgents.IE], &#39;MSIE&#39;);
<a name="line170"></a>  assertEquals(&#39;ms&#39;, goog.dom.vendor.getVendorJsPrefix());
<a name="line171"></a>}
<a name="line172"></a>
<a name="line173"></a>
<a name="line174"></a>/**
<a name="line175"></a> * Tests for the vendor Js prefix if no UA detected.
<a name="line176"></a> */
<a name="line177"></a>function testVendorJsPrefixNone() {
<a name="line178"></a>  assertUserAgent([], &#39;&#39;);
<a name="line179"></a>  assertNull(goog.dom.vendor.getVendorJsPrefix());
<a name="line180"></a>}
<a name="line181"></a>
<a name="line182"></a>
<a name="line183"></a>/**
<a name="line184"></a> * Tests for the prefixed property name on Webkit.
<a name="line185"></a> */
<a name="line186"></a>function testPrefixedPropertyNameWebkit() {
<a name="line187"></a>  assertUserAgent([UserAgents.WEBKIT], &#39;WebKit&#39;);
<a name="line188"></a>  assertEquals(&#39;webkitFoobar&#39;,
<a name="line189"></a>      goog.dom.vendor.getPrefixedPropertyName(&#39;foobar&#39;));
<a name="line190"></a>}
<a name="line191"></a>
<a name="line192"></a>
<a name="line193"></a>/**
<a name="line194"></a> * Tests for the prefixed property name on Webkit in an object.
<a name="line195"></a> */
<a name="line196"></a>function testPrefixedPropertyNameWebkitAndObject() {
<a name="line197"></a>  var mockDocument = {
<a name="line198"></a>    // setting a value of 0 on purpose, to ensure we only look for property
<a name="line199"></a>    // names, not their values.
<a name="line200"></a>    &#39;webkitFoobar&#39;: 0
<a name="line201"></a>  };
<a name="line202"></a>  assertUserAgent([UserAgents.WEBKIT], &#39;WebKit&#39;);
<a name="line203"></a>  assertEquals(&#39;webkitFoobar&#39;,
<a name="line204"></a>      goog.dom.vendor.getPrefixedPropertyName(&#39;foobar&#39;, mockDocument));
<a name="line205"></a>}
<a name="line206"></a>
<a name="line207"></a>
<a name="line208"></a>/**
<a name="line209"></a> * Tests for the prefixed property name.
<a name="line210"></a> */
<a name="line211"></a>function testPrefixedPropertyName() {
<a name="line212"></a>  assertUserAgent([], &#39;&#39;);
<a name="line213"></a>  assertNull(goog.dom.vendor.getPrefixedPropertyName(&#39;foobar&#39;));
<a name="line214"></a>}
<a name="line215"></a>
<a name="line216"></a>
<a name="line217"></a>/**
<a name="line218"></a> * Tests for the prefixed property name in an object.
<a name="line219"></a> */
<a name="line220"></a>function testPrefixedPropertyNameAndObject() {
<a name="line221"></a>  var mockDocument = {
<a name="line222"></a>    &#39;foobar&#39;: 0
<a name="line223"></a>  };
<a name="line224"></a>  assertUserAgent([], &#39;&#39;);
<a name="line225"></a>  assertEquals(&#39;foobar&#39;,
<a name="line226"></a>      goog.dom.vendor.getPrefixedPropertyName(&#39;foobar&#39;, mockDocument));
<a name="line227"></a>}
<a name="line228"></a>
<a name="line229"></a>
<a name="line230"></a>/**
<a name="line231"></a> * Tests for the prefixed property name when it doesn&#39;t exist.
<a name="line232"></a> */
<a name="line233"></a>function testPrefixedPropertyNameAndObjectIsEmpty() {
<a name="line234"></a>  var mockDocument = {};
<a name="line235"></a>  assertUserAgent([], &#39;&#39;);
<a name="line236"></a>  assertNull(goog.dom.vendor.getPrefixedPropertyName(&#39;foobar&#39;, mockDocument));
<a name="line237"></a>}
<a name="line238"></a>
<a name="line239"></a>
<a name="line240"></a>/**
<a name="line241"></a> * Test for prefixed event type.
<a name="line242"></a> */
<a name="line243"></a>function testPrefixedEventType() {
<a name="line244"></a>  assertUserAgent([], &#39;&#39;);
<a name="line245"></a>  assertEquals(&#39;foobar&#39;, goog.dom.vendor.getPrefixedEventType(&#39;foobar&#39;));
<a name="line246"></a>}
<a name="line247"></a>
<a name="line248"></a>
<a name="line249"></a>/**
<a name="line250"></a> * Test for browser-specific prefixed event type.
<a name="line251"></a> */
<a name="line252"></a>function testPrefixedEventTypeForBrowser() {
<a name="line253"></a>  assertUserAgent([UserAgents.WEBKIT], &#39;WebKit&#39;);
<a name="line254"></a>  assertEquals(&#39;webkitfoobar&#39;, goog.dom.vendor.getPrefixedEventType(&#39;foobar&#39;));
<a name="line255"></a>}
<a name="line256"></a>
<a name="line257"></a>
<a name="line258"></a>function assertIe(uaString, expectedVersion) {
<a name="line259"></a>  assertUserAgent([UserAgents.IE], uaString);
<a name="line260"></a>  assertEquals(&#39;User agent &#39; + uaString + &#39; should have had version &#39; +
<a name="line261"></a>      expectedVersion + &#39; but had &#39; + goog.userAgent.VERSION,
<a name="line262"></a>      expectedVersion,
<a name="line263"></a>      goog.userAgent.VERSION);
<a name="line264"></a>}
<a name="line265"></a>
<a name="line266"></a>
<a name="line267"></a>function assertGecko(uaString, expectedVersion) {
<a name="line268"></a>  assertUserAgent([UserAgents.GECKO], uaString, &#39;Gecko&#39;);
<a name="line269"></a>  assertEquals(&#39;User agent &#39; + uaString + &#39; should have had version &#39; +
<a name="line270"></a>      expectedVersion + &#39; but had &#39; + goog.userAgent.VERSION,
<a name="line271"></a>      expectedVersion,
<a name="line272"></a>      goog.userAgent.VERSION);
<a name="line273"></a>}
</pre>


</body>
</html>
